<?php

/* $Id: Browse.class.php 120 2008-05-05 22:34:49Z joshuarudd $ */

class Browse
{
	private $cms;
	private	$db;
	
	public function __construct($p)
	{
		$this->cms = $p;
		$this->db = $this->cms->db;
		
	}
	
	public function buildPage()
	{
		$table = $this->cms->table;
		
		$q_label = $this->db->queryRow("SELECT display_name,menu_id FROM ".BLACKBIRD_TABLE_PREFIX."tables WHERE table_name = '$table'");
		if($q_label['display_name'] == ''){
			$label = Utils::formatHumanReadable($table);
		}else{
			$label = $q_label['display_name'];
		}
		
		print '
		<div id="bb_toolbar">
			<h1>'.$label.'</h1>
			<!--
			<dl id="bb_record_meta">
				<dt>Id</dt>
				<dd>268</dd>
				<dt>Created</dt>
				<dd>2008-04-01 14:26:37</dd>
				<dt>Modified</dt>
				<dd>2008-04-025 10:03:58</dd>
			</dl>
			-->
			<div id="bb_record_actions">
				<input type="button" value="+ New Record" onclick="window.location=\''.BLACKBIRD_ROOT.'add/'. $table.'\'" />
			</div>
		</div>
		
		
		<div id="bb_module" class="browse">
		<div id="pane_main">
		
		';
		
		print '<div class="data_grid_embed">';
		
		$name_space = 'main';
		$config = '';
		$relation = '';
		
		include_once(INCLUDES.'DataGridAjax.class.php');
		$module = new DataGridAjax($this->cms);
		$module->cms = $this->cms;
		$module->table = $this->cms->table;
		$module->name_space = $name_space;
		$module->config = $config;
		$module->build();
		
		print '</div>
		</div>
		</div>';
		
		print '
		<script type="text/javascript">
			<!-- <![CDATA[ 
			var data_grid_' . $name_space . '= new dataGrid(
				{ 	
					table: \'' . $this->cms->table . '\',
					name_space: \''.$name_space.'\',
					cms_root: \'' . BLACKBIRD_ROOT . '\',';
					print '
				}
			);
			CMS.broadcaster.addListener(data_grid_'.$name_space.'.listener);
			CMS.addCallback(\'' . $name_space . '\',data_grid_'.$name_space.',"getUpdate");
			// ]]> -->
		</script>';
	}
}